--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_art_fam AS (SELECT * FROM &erp.ART_FAM WHERE 1=2);




DELETE FROM se_art_fam;

 INSERT INTO se_art_fam
 (SELECT   ID,
           POSTEANA,
           SECTANA,
           NULL,
           NOMCEE,
           NULL,
           'N',
           LIBELLE,
           NULL,
           Decode(PERTE,NULL,1,(PERTE+100)/100),
           COEFMAT
    FROM uv_pfamilles) ;

 UPDATE se_art_fam tf SET enreg_id=(select enreg_id FROM &erp.art_fam f WHERE f.fam_cod=tf.fam_cod) ;
 UPDATE se_art_fam tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('enreg_id','ART_FAM','O') ;

 commit;
 
 
 
select * from (
SELECT &outils.stragg(source) source,fam_cod, sfam_cod, enreg_id, destana_cod, postana_cod, cptafam_cod, nomen_cod, enreg_s, sfam_lib, sfam_lib2, rebut_coef, ponderationpx_coef
FROM (
  SELECT 'uv' source ,g.* FROM se_art_sfam g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.art_sfam g
  )
GROUP BY fam_cod, sfam_cod, enreg_id, destana_cod, postana_cod, cptafam_cod, nomen_cod, enreg_s, sfam_lib, sfam_lib2, rebut_coef, ponderationpx_coef
HAVING Count(1)!=2) r
ORDER BY fam_cod,sfam_cod;